﻿#region

using System;
using System.ComponentModel;
using System.Text;
using System.Web.Mvc;
using HouseHoldBudget.Core.Extensions;

#endregion

namespace HouseHoldBudget.Framework.Mvc.Helpers
{
    public static class UrlHelperExtension
    {
        #region Class Methods

        public static string GeneralParameters(this UrlHelper helper)
        {
            return helper.RouteUrl("GeneralParameters");
        }

        public static string Home(this UrlHelper helper)
        {
            return helper.Content("~/");
        }

        public static string Image(this UrlHelper helper, string filename)
        {
            return String.Format("/Content/Images/{0}", filename);
        }

        public static string Image(this UrlHelper helper, Uri uri)
        {
            if (uri != null)
                return String.Format("/Content/Images/{0}", uri.OriginalString);
            return string.Empty;
        }

        public static string Layout(this UrlHelper helper)
        {
            return helper.Content("~/Views/Shared/_Layout.cshtml");
        }

        public static string LogOff(this UrlHelper helper)
        {
            return helper.Content("~/Account/LogOff");
        }

        public static string LogOn(this UrlHelper helper)
        {
            return helper.RouteUrl("~/Account/LogOn");
        }

        public static string Script(this UrlHelper helper, ScriptCategory scriptCategory, string filename)
        {
            StringBuilder sb = new StringBuilder("~/Content/Scripts/");

            if (scriptCategory != ScriptCategory.Root)
                sb.AppendFormat("{0}/", scriptCategory.GetDescription());

#if DEBUG
            sb.AppendFormat("{0}.js", filename);
#else
            switch (scriptCategory)
            {
                case ScriptCategory.Views:
                case ScriptCategory.Extensions:
                case ScriptCategory.KendoUI:
                    sb.AppendFormat("{0}.min.js", filename);
                    break;
                default:
                    sb.AppendFormat("{0}.js", filename);
                    break;
            }
#endif

            return helper.Content(sb.ToString());
        }

        public static string Script(this UrlHelper helper, Uri scriptUri)
        {
            return helper.Content(scriptUri.ToString());
        }

        public static string Style(this UrlHelper helper, StyleCategory styleCategory, string filename)
        {
            StringBuilder sb = new StringBuilder("~/Content/Styles/");

            if (styleCategory != StyleCategory.Root)
                sb.AppendFormat("{0}/", styleCategory.GetDescription());

#if DEBUG
            sb.AppendFormat("{0}.css", filename);
#else
            sb.AppendFormat(styleCategory == StyleCategory.View ? "{0}.min.css" : "{0}.css", filename);
#endif

            return helper.Content(sb.ToString());
        }

        public static string Style(this UrlHelper helper, Uri styleUri)
        {
            return helper.Content(styleUri.ToString());
        }

        #endregion
    }

    public enum StyleCategory
    {
        [Description("")] Root,

        [Description("KendoUI")] KendoUI,

        [Description("Views")] View,

        [Description("Telerik")] Telerik
    }

    public enum ScriptCategory
    {
        [Description("")] Root,

        [Description("JQuery")] JQuery,

        [Description("JQueryUI")] JQueryUi,

        [Description("KendoUI")] KendoUI,

        [Description("Microsoft")] Microsoft,

        [Description("Modernizr")] Modernizr,

        [Description("Views")] Views,

        [Description("Css3Pie")] Css3Pie,

        [Description("Notifier")] Notifier,

        [Description("Extensions")] Extensions,

        [Description("Telerik")] Telerik
    }
}